<template>
  <div class="app-container">
    <!-- 添加或修改对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="800px" v-if="open" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-row :gutter="60">
          <el-col :span="12">
            <el-form-item label="家长" prop="userId">
              <group-select class="form-item-input-style" v-model="form.userId" :group_list="['user']"
                :group_query="userGroupQuery" placeholder="请选择家长" />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" v-if="!disabled" @click="submitForm">确 定</el-button>
        <el-button @click="cancel" v-if="!disabled">取 消</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
import { bindingUser } from "@/api/jiaopei/student";
import groupSelect from "@/views/components/groupSelect";
import store from '@/store'
export default {
  name: "bindParents",
  components: {
    groupSelect,
  },
  computed: {
    userGroupQuery() {
      var value = {
        'user': {
          teacher: '3'
        }
      }
      return value
    }
  },
  data() {
    return {
      fileType: ['mp4', 'flv'],
      // 是否禁用表单
      disabled: false,
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        userId: [
          { required: true, message: "家长不能为空", trigger: "blur" }
        ],
      }
    };
  },
  methods: {
    /** 打开资产记录弹框 */
    async show(id, disabled, form) {
      this.reset();
      this.disabled = disabled
      this.form = this.$common.deepMergeExistingProperties(this.form, form);

      if (this.disabled) {
        this.title = "绑定家长"
      } else if (id) {
        
        this.title = "绑定家长"
      } else {
        this.title = "绑定家长"
      }
      this.open = true
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      const date = new Date();
      this.form = {
        studentId: undefined,
        userId: undefined,
      };
      this.resetForm("form");
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
            bindingUser(this.form).then(response => {
              this.$modal.msgSuccess("操作成功");
              this.open = false;
              this.$emit('refresh');
            });
        }
      });
    }
  }
};
</script>
